﻿using System;
using System.Collections.Generic;
using System.Windows.Input;
//
// Mp3Cleaner, Copyright Mirosław M. Mączka.  All Rights Reserved. This code released under the terms of the Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)
//
namespace Mp3Cleaner
{
    public class WaitingTooLong
    {
        private DateTime dt = DateTime.MinValue;
        private TimeSpan ts = TimeSpan.Zero;
        //
        public WaitingTooLong(int seconds)
        {
            this.ts = TimeSpan.FromSeconds((double)seconds);
            this.dt = DateTime.Now;
        }
        public void Start(int seconds)
        {
            this.ts = TimeSpan.FromSeconds((double)seconds);
            this.dt = DateTime.Now;
        }
        public bool isTooLong()
        {
            return (dt + ts) < DateTime.Now;
        }
        public bool isTooLongBeep(IntPtr hWnd)
        {
            if (isTooLong())
            {
                if (IntPtr.Zero != hWnd)
                {
                    FlashWindow.FlashWindow.Blink(hWnd, 2);
                }
                System.Media.SystemSounds.Beep.Play();
                return true;
            }
            return false;
        }
    }//class


    public class StackedCursorOverride : IDisposable
    {
        private readonly static Stack<Cursor> CursorStack;

        static StackedCursorOverride()
        {
            CursorStack = new Stack<Cursor>();
        }

        public StackedCursorOverride(Cursor cursor)
        {
            CursorStack.Push(cursor);
            Mouse.OverrideCursor = cursor;
        }

        public void Dispose()
        {
            var previousCursor = CursorStack.Pop();
            if (CursorStack.Count == 0)
            {
                Mouse.OverrideCursor = null;
                return;
            }

            // if next cursor is the same as the one we just popped, don't change the override 
            if ((CursorStack.Count > 0) && (CursorStack.Peek() != previousCursor))
                Mouse.OverrideCursor = CursorStack.Peek();
        }
    }

}
